/* util */
import { isArray } from '@src/util/type'
/* model */
import { 
  SelectUserComponentUser, 
  SelectUserComponentDepartment, 
  SelectUserComponentRole, 
  SelectUserComponentServiceProvider
} from '@src/component/common/BaseSelectUser/model/interface'
/* type */
import { BaseSelectUserSelectedItemType } from '@src/component/common/BaseSelectUser/types'

class BaseSelectUserTree {
  id: string = ''
  // 头像
  logo: string = '';
  // 类型 id
  typeId: number | null = null;
  // 服务商名称
  name: string = '';
  // 当前下的人员数量
  userCount: number | null = null;
  // 子级
  tagChildren: BaseSelectUserTree[] = [];
  // 是否只是用来显示的，不可选择，点击不会触发事件
  isOnlyDisplay: boolean = false;
}

/**
 * @description 选择组件返回数据结果
 */
class BaseSelectUserResult {
  
  // 用户列表
	public users: SelectUserComponentUser[] = []
  // 部门列表
  public depts: SelectUserComponentDepartment[] = []
  // 角色列表
  public roles: SelectUserComponentRole[] = []
  // 服务商列表
  public serviceProviders: SelectUserComponentServiceProvider[] = []
  // 所有选择列表
  public all: BaseSelectUserSelectedItemType[] = []
  
  // 部门列表
  public get departments(): SelectUserComponentDepartment[] {
    return this.depts
  }
  
  // 用户 id 列表
  public get userIds(): string[] {
		return this.users.map(user => user.userId)
	}
  
  // 部门 id 列表
  public get deptIds() {
    return this.depts.map(dept => dept.id)
  }
  
  // 部门 id 列表
  public get departmentIds() {
    return this.deptIds
  }
  
  // 角色 id 列表
  public get roleIds() {
    return this.roles.map(role => role.id)
  }
  
  // 服务商 id 列表
  public get serviceProviderIds() {
    return this.serviceProviders.map(serviceProvider => serviceProvider.id)
  }
  
	constructor(
    users: SelectUserComponentUser[] = [],
    depts: SelectUserComponentDepartment[] = [],
    roles: SelectUserComponentRole[] = [],
    serviceProviders: SelectUserComponentServiceProvider[] = [],
    all: BaseSelectUserSelectedItemType[] = []
  ) {
    this.users = isArray(users) ? users : []
    this.depts = isArray(depts) ? depts : []
    this.roles = isArray(roles) ? roles : []
    this.serviceProviders = isArray(serviceProviders) ? serviceProviders : []
    this.all = isArray(all) ? all : []
	}
  
}

export {
  BaseSelectUserResult,
  BaseSelectUserTree
}